import Dialog from '@vant/weapp/dialog/dialog'

Page({
  data: {
    list: [],
    dialogVisible: false,
  },

  onShow() {
   this.getList()
  },
  async getList(){
    const res = await wx.http({ url: '/room' })
    console.log(res,'111');
    this.setData({ list: res.data })
  },

  async swipeClose(e) {
    const { position, instance } = e.detail

     try{
      if (position === 'right') {
        // 显示 Dialog 对话框
       await Dialog.confirm({
        title:'删除此项吗？'
       })
       await wx.http({method:'delete',url:'/room/'+e.mark.id})
       wx.utils.toast('删除成功')
       await this.getList()
      }
     }
     finally{
      instance.close()
     }
  },

  goDetail(e) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id='+ e.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
